package store.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 账号信息
 */
public class Account {

    private Integer id;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 密码
     */
    private String password;

    private boolean type;

    /**
     * 姓名
     */
    private String name;

    /**
     * 积分
     */
    private int point;

    /**
     * 余额
     */
    private double money;

    /**
     * 会员等级
     */
    //private Level level;
    private Date createTime;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean isType() {
        return type;
    }

    public void setType(boolean type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPoint() {
        return point;
    }

    public void setPoint(int point) {
        this.point = point;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * 购物车
     */
    //private ArrayList<Treasure> shopCar;


    public static class AccountRecover implements Recover<Account> {

        @Override
        public List<Account> recover(ResultSet set) throws SQLException {
            List<Account> list = new ArrayList<>();
            while (set.next()) {
                Account account = new Account(set.getInt("id"),
                        set.getString("phone"),
                        set.getString("password"),
                        set.getBoolean("type"),
                        set.getString("name"),
                        set.getInt("point"),
                        set.getDouble("money"),
                        set.getDate("create_time"));
                list.add(account);
            }
            return list;
        }
    }

    public Account() {}
    public Account(Integer id, String phone, String password, boolean type, String name, int point, double money, Date createTime) {
        this.id = id;
        this.phone = phone;
        this.password = password;
        this.type = type;
        this.name = name;
        this.point = point;
        this.money = money;
        this.createTime = createTime;
    }

//public boolean login(Account account) {
    //    if (this.getPhone().equals(account.getPhone()) && this.getPassword().equals(account.getPassword())){
    //        return true;
    //    }
    //    return false;
    //}


    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    //public ArrayList<Treasure> getShopCar() {
    //    return shopCar;
    //}
    //
    //public void setShopCar(ArrayList<Treasure>  shopCar) {
    //    this.shopCar = shopCar;
    //}
}
